﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class test
    {
        private readonly string sqlCommandString = "select * from Student";
        private readonly string connectionString = "server=; user=sa ;pwd=123456;database=Studen4";
        public static void Student()
        {
            string connectionSring = "server=; user=sa ;pwd=123456;database=Student4";
            SqlConnection sqlConnection = new SqlConnection(connectionSring);
            sqlConnection.Open();
            string sqlCommandString = "se;ect * from Student";
            SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
            var sdr = sqlCommand.ExecuteReader();
            Console.WriteLine("(0)\t(1)\t(2)","Id","姓名","成绩") ;

            while (sdr.Read())
            {
                Console.WriteLine("(0)\t(1)\t(2)", sdr["StuId"], sdr["Studentname"], sdr["score"]);
            }
            sqlConnection.Close();
        }
        public void Students()
        {
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommandString, connectionString);

            System.Data.DataTable dataTable = new System.Data.DataTable();

            dataAdapter.Fill(dataTable);
            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t{2}", "Id", "姓名", "成绩");

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}", dataTable.Rows[i]["StuId"], dataTable.Rows[i]["Studentname"], dataTable.Rows[i]["Score"]);
            }

        }
    }
}
